#!/usr/bin/env python
# -*- coding: utf-8 -*-
class ItemType():
    
    def __init__(self, name, description, model,
                 show_view, add_view, add_document_view, delete_view,
                 change_view, render_add_item, render_add_document_item,
                 render_show_item):
        self.name = name
        self.description = description
        self.model = model
        self.show_view = show_view
        self.add_view = add_view
        self.add_document_view = add_document_view
        self.delete_view = delete_view
        self.change_view = change_view
        self.render_add_item = render_add_item
        self.render_add_document_item = render_add_document_item
        self.render_show_item = render_show_item

    @property
    def identifier(self):
        return self.model.__name__
    
    # contains all registered item_types
    # for static usage only
    item_types = set()
    
    # TODO: Idea: manage this via annotations!
    def register(self):
        """
        Registers the item_type
        """
        ItemType.item_types.add(self)

    @staticmethod
    def get_item_type_for_identifier(identifier):
        """
        Returns an itemtype corresponding to an ItemType name
        """
        for item_type in ItemType.item_types:
            if(item_type.identifier == identifier):
                return item_type
            
        return None
    
    @staticmethod
    def get_item_type_for_model(model):
        """
        Returns an itemtype corresponding to a Model
        """
        for item_type in ItemType.item_types:
            if(item_type.model == model):
                return item_type
            
        return None